package com.meiyu.live.ui.mine;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.android.volley.Response;
import com.meiyu.live.BaseActivity;
import com.meiyu.live.R;
import com.meiyu.live.comm.Constant;
import com.meiyu.live.net.param.FeedbackParams;
import com.meiyu.live.net.response.BaseResponse;
import com.meiyu.live.util.ToastUtil;
import com.meiyu.live.widget.NetLoadingDailog;

/**
 * Created by zbl on 2016/9/22.
 */
public class AdviceActivity extends BaseActivity implements View.OnClickListener {

    protected NetLoadingDailog dialog_loading;
    private View btn_back;
    private TextView btn_send;
    private EditText et_content;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_advice);
        init();
    }

    private void init() {
        dialog_loading = new NetLoadingDailog(this);
        btn_back = findViewById(R.id.btn_back);
        btn_back.setOnClickListener(this);
        btn_send = (TextView) findViewById(R.id.btn_send);
        btn_send.setOnClickListener(this);
        et_content = (EditText) findViewById(R.id.et_content);
    }

    @Override
    public void onClick(View view) {
        if (view == btn_back) {
            finish();
        } else if (view == btn_send) {
            postData(et_content.getText().toString().trim());
        }
    }


    private void postData(final String content) {
        if (TextUtils.isEmpty(content)) {
            ToastUtil.show("请输入建议内容");
            return;
        }
        dialog_loading.loading();
        request(new FeedbackParams(content), BaseResponse.class, new Response.Listener<BaseResponse>() {
            @Override
            public void onResponse(BaseResponse onlyStatusResponse) {
                dialog_loading.dismissDialog();
                if (onlyStatusResponse.getStatusCode() == Constant.StatusCode_Success){
                    ToastUtil.show("意见提交成功，感谢您的反馈！");
                    finish();
                }else{
                    ToastUtil.show("提交失败");
                }
            }
        });
    }


    @Override
    public void onBackPressed() {
        super.onBackPressed();
    }

    @Override
    public void onError() {
        super.onError();
        dialog_loading.dismissDialog();
    }
}
